package lc20240517;

//Definition for a binary tree node.


//是否是两个相同的树。
public class Demo1 {
    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        treeNode1.left=new TreeNode(2);
        treeNode1.right=new TreeNode(1);

        TreeNode treeNode2 = new TreeNode(1);
        treeNode2.left=new TreeNode(2);
        treeNode2.right=new TreeNode(1);
        System.out.println(isSameTree(treeNode1, treeNode2));
    }
    public static boolean isSameTree(TreeNode p, TreeNode q) {
        if (p==null&&q==null){
            return true;
        }
        //有一个节点是null，返回false
        if (p==null||q==null){
            return false;
        }
        if (p.val!=q.val){
            return false;
        }
        return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
    }
}
